package com.njupt.webapp.tags;

import javax.servlet.jsp.JspException;

import org.springframework.jdbc.core.JdbcTemplate;


/**
 * 输入sql语句，返回一个Object。
 *
 */
@SuppressWarnings("serial")
public class SqlQueryForObjectTag extends SqlBaseTag{

	protected String klass;
	
	public int doStartTag() throws JspException {
        String sqlx = (String) TagUtils.evaluate("sql",sql, String.class,this,pageContext);
        klass = (String) TagUtils.evaluate("klass",klass, String.class,this,pageContext);
        JdbcTemplate template = super.getTemplate();
		try{
			Object o = template.queryForObject(sqlx, Class.forName(klass));
			TagUtils.saveToContext(this,pageContext,scope,o);
		}catch(Exception e){
			e.printStackTrace();
		}

        return super.doStartTag();
  
	}

	public String getKlass() {
		return klass;
	}
	public void setKlass(String klass) {
		this.klass = klass;
	}
	
}
